using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using eYap.src.Forms;
using eYap.src;

namespace eYap
{
    public partial class AccountManager : Form
    {
        MainForm parentForm;
        ImageList ProtocolImages;

        public AccountManager(MainForm form)
        {
            InitializeComponent();
            ProtocolImages = new ImageList();
            ProtocolImages.ImageSize = new Size(30, 30);
            lstView_Accounts.LargeImageList = ProtocolImages;

            this.parentForm = form;
            PopulateAccountList();
        }

        public void PopulateAccountList()
        {
            lstView_Accounts.Items.Clear();

            foreach (Account acc in SettingsManager.ACCOUNTS)
            {
                if (acc.protocol == SettingsManager.Protocol.Facebook)
                {
                    ProtocolImages.Images.Add(eYap.Properties.Resources.facebook_logo_small);
                    ListViewItem item = new ListViewItem(acc.username);
                    item.ImageIndex = ProtocolImages.Images.Count - 1;
                    lstView_Accounts.Items.Add(item);
                }
            }
        }

        private void btn_AddAccount_Click(object sender, EventArgs e)
        {
            AddAccountControl aac = new AddAccountControl(this);
            this.gBox_AccActions.Controls.Add(aac);
            aac.Show();
            btn_AddAccount.Hide();
            btn_RemAccount.Hide();
            btn_EditAccount.Hide();
        }

        private void btn_RemAccount_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lstView_Accounts.Items)
            {
                if (item.Selected)
                {
                    SettingsManager.RemoveAccount(item.Text);
                    lstView_Accounts.Items.Remove(item);
                    break;
                }
            }
            
            PopulateAccountList();
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            parentForm.PopulateProtocolComboBox();
            this.Close();
        }
    }
}